package cn.webrx.coll;/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>Project: jse2204 - cn.webrx.coll.ArrayList6
 * <p>Powered by webrx On 2022-09-19 11:23:53
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrayList6 {

    public static void main(String[] args) {
        //自定义对象 排序
        List<Student> s = new ArrayList<>(List.of(
                new Student(10, "李四", 30, "郑州"),
                new Student(11, "张三", 90, "天津"),
                new Student(12, "李丽", 60, "郑州"),
                new Student(23, "张三丰", 80, "北京"),
                new Student(36, "王五", 20, "郑州"),
                new Student(100, "赵六", 10, "上海"),
                new Student(9, "李强", 39, "上海"),
                new Student(1, "李三", 99, "上海"),
                new Student(11000, "李磊", 89, "上海")
        ));

        System.out.println(s);

        Collections.shuffle(s);
        System.out.println(s);

        //Collections.sort(s); 这一行有错误，Student对象没有实现排序接口的相关的方法

        //Collections.sort(s,(a,b)->b.getId()-a.getId());
        //System.out.println(s);

        //Collections.sort(s,(a,b)->a.getName().compareTo(b.getName()));
        //System.out.println(s);

        //Collections.sort(s,(a,b)->b.getName().length() - a.getName().length());
        //System.out.println(s);


        //如果类实现了Comparable<cn.webrx.coll.Student>接口并实现了方法compareTo()
        //根据id的升序
        Collections.sort(s);
        System.out.println(s);


        Collections.sort(s,(o1,o2)->o2.getId()-o1.getId());
        System.out.println(s);




    }


    public static void test(String[] args) {
        var s1 = new Student(11, "李四", 80, "郑州");
        var s2 = new Student(11, "李四", 80, "郑州");

        //只jvm虚拟机中的实例对象的id值
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));

    }
}
